import requests
import settings


class SendAPiUtil:
    """
        发生api工具
    """
    def __init__(self):
        self.session = requests.Session()
        self.base_url = settings.BASE_URL
        self.timeout = settings.TIMEOUT

    def send_api(self, method, url, **kwargs):
        try:
            full_url = self.base_url + url
            
            return self.session.request(
                    method, 
                    full_url, 
                    timeout=self.timeout, 
                    **kwargs
                )
        except Exception as e:
            print(f"接口发送失败: {e}")


if __name__ == "__main__":
    sendapi = SendAPiUtil()
    response = sendapi.send_api(
        method="get",
        url="/pet",
    )
    print(response.text)